<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head>
  <meta charset="UTF-8">
  <title>JavaScript Let</title>
</head>
<body>

<h1>JavaScript 局部作用域</h1>

<p>myFunction() 之外的 carName 未定义。</p>

<p id="demo1"></p>

<p id="demo2"></p>

<script>
  myFunction();

  function myFunction(){
    var carName="porsche";
    document.getElementById("demo1").innerHTML=
            typeof carName+" "+carName;
  }
  // typeof 字符串类型返回string

  document.getElementById("demo2").innerHTML=typeof carName;
</script>
</body>
</html>